/**
* <p>Title: SenderReceiveHandler.java</p>
* <p>Description: </p>
* <p>Company: www.huoyunren.com</p>
* @author duanxiangyun
* @date 2015年4月24日
* @version 1.0
*/
package com.hxbd.test.utils;

import org.apache.commons.codec.binary.Hex;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class SenderReceiveHandler  extends IoHandlerAdapter {
	public static String seqno="";
	public static String msgid="";
	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		// TODO Auto-generated method stub
		// super.messageReceived(session, message);
		byte[] byArr = (byte[]) message;
		System.out.print("dsp返回的响应 :");
		char[] chArr = Hex.encodeHex(byArr);
		String str="";
		int i = 0;
		for (char c : chArr) {
			System.out.print(String.valueOf(c).toUpperCase());
			if((i++)%2 != 0){
				System.out.print(" ");
			}str+=String.valueOf(c).toUpperCase();
		}
//		if(str.length()==126){
//			seqno=str.substring(36, 40);
//		}
		if("8300".equals(str.substring(2, 6))){
			msgid=str.substring(2, 6);
			seqno=str.substring(22, 26);
		}
//		System.out.println("");
//		System.out.println("msg id="+str.substring(2, 6));
		System.out.println("");
		// session.write("mymina1设备收到消息再次发送消息");
	}

	@Override
	public void sessionClosed(IoSession session) throws Exception {
		// TODO Auto-generated method stub
		super.sessionClosed(session);
	}

	@Override
	public void sessionIdle(IoSession session, IdleStatus status)
			throws Exception {
		// TODO Auto-generated method stub
		super.sessionIdle(session, status);
	}

	@Override
	public void messageSent(IoSession session, Object message) throws Exception {

		System.out.println("messageSent" + message.toString());
		// super.messageSent(session, message);
	}

	@Override
	public void sessionCreated(IoSession session) throws Exception {

		super.sessionCreated(session);
	}

	@Override
	public void sessionOpened(IoSession session) throws Exception {
		super.sessionOpened(session);
	}
	
}
